package cn.gson.crm.control.total;

import java.util.List;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.gson.crm.control.base.BaseServlet;
import cn.gson.crm.model.dao.PaymenterDao;
import cn.gson.crm.model.entity.Position;
import cn.gson.crm.model.entity.Student;
import cn.gson.crm.model.entity.StudentService;

/**
 * Servlet implementation class addPaymenterServlet
 */
@WebServlet("/addpaymenter")
public class addPaymenterServlet extends BaseServlet {
	private static final long serialVersionUID = 1L;
    private PaymenterDao pd=new PaymenterDao();
	@Override
	protected void get(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String p = request.getParameter("page");
		String studentName = request.getParameter("studentName");
		if (p == null || p.isEmpty()) {
			p = "1";
		}
		//List<Position>delList=pd.getDelJob(1);
		Integer page = Integer.parseInt(p);
		// 当前页数据
		List<StudentService> studentList = pd.getPageStudentListByType(page, studentName);
		// 总页数
		int totalPage = pd.getTotalPage(studentName);
		request.setAttribute("queryString", noPageQueryString());
		request.setAttribute("studentList", studentList);
		request.setAttribute("totalPage", totalPage);
		request.setAttribute("page", page);
		//request.setAttribute("delList", delList);
		forward("total/addpaymenter.jsp");
	}
	@Override
	protected void post(HttpServletRequest request, HttpServletResponse response) throws Exception {
		String studentids=request.getParameter("studentids");
		String studentallotids=request.getParameter("studentallotids");
		String ifloans=request.getParameter("ifloans");
		String totalMoney=request.getParameter("totalMoney");
		String loanMoney=request.getParameter("loanMoney");
		String totalTerm=request.getParameter("totalTerm");
		Double totalNoMoney =null;
		if (loanMoney==null||loanMoney.isEmpty()) {
			totalNoMoney=Double.parseDouble(totalMoney);
		}else {
			totalNoMoney=Double.parseDouble(totalMoney)-Double.parseDouble(loanMoney);
		}
		if(pd.addTotalData(
				Integer.parseInt(studentids),
				Integer.parseInt(studentallotids),
				Integer.parseInt(totalTerm),
				Integer.parseInt(ifloans),
				Double.parseDouble(totalMoney),
				totalNoMoney)){
			redirect("total");
		}
	}
}
